<template>
  <div class="app-container">
    <el-dialog :title="title" :visible.sync="open" width="960px" append-to-body>
      <el-table v-loading="loading" :data="placeList">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="地点编号" align="center" prop="placeOdd" />
        <el-table-column label="地点名称" align="center" prop="placeName" />
        <el-table-column label="巡检日期" align="center" prop="patrolDate">
          <template slot-scope="scope">
            <span v-if="scope.row.patrolDate == 1">连续每天</span>
            <span v-if="scope.row.patrolDate == 2">连续每周</span>
            <span v-if="scope.row.patrolDate == 3">连续每月</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleOff(scope.row)" v-hasPermi="['waitress:CruiserTask:updCruiserOff']">
              <span v-if="countState !== '0'">巡检打卡</span>
              <span v-else>查看</span>
            </el-button>
          </template>
        </el-table-column>
    </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <CruiserTaskForm ref="formRef" @cancel="getList" />
  </div>
</template>

<script>

import { listMixin } from "@/utils/mixins/listMixin";
import { listPathDetail } from "@/api/waitress/PathDetail";
import PlaceForm from "./form.vue"
import { listCommunity} from "@/api/property/community";
import CruiserTaskForm from "./form.vue"
import { listCruiserTaskDetail, getCruiserTaskDetail } from "@/api/waitress/CruiserTaskDetail";

export default {
  name: "Place",
  components:{ PlaceForm,CruiserTaskForm },
  mixins:[ listMixin ],
  dicts: [   'place_state',   ],
  data() {
    return {
      // 地点管理表格数据
      placeList: [],
      currentNode:{},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否禁用
      disabled: false,
      // 表单参数
      form: {},
      placeId: '',
      communityOptions:[],
      CruiserTaskDetailList: [],
      countState: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        communityId: null,
        placeName: null,
        placeOdd: null,
        cruiserAsk: null,
        ancestors: null,
        deptId: null,
        nodeId:null,
      },
      // 表单校验
      rules: {
        communityId: [
          { required: true, message: "小区ID不能为空", trigger: "blur" }
        ],
        placeName: [
          { required: true, message: "地点名称不能为空", trigger: "blur" }
        ],
        cruiserAsk: [
          { required: true, message: "巡逻要求不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    listCommunity().then(res=>{
      this.communityOptions = res.rows;
    });
  },
  methods: {
    show(options){
      this.countState = options.stateCount
      this.placeId = options.id
      this.queryParams.pathId = options.pathId || -1
      this.open = true
      this.title = `路线详情`
      this.getList();
      this.getCruiserTaskDetailList();
    },
    /** 查询地点管理列表 */
    getList() {
      this.loading = true;
      listPathDetail(this.queryParams).then(response => {
        this.placeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getCruiserTaskDetailList() {
      listCruiserTaskDetail({'taskId': this.placeId}).then(response => {
        this.CruiserTaskDetailList = response.rows;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.$emit("cancel");
      this.getList();
    },
    handleOff(row){
      const hh = this.CruiserTaskDetailList.filter(item => {
        if (item.placeId == row.placeId) {
          return item
        }
      })
      const id = hh[0].id
      const option = {
        "type":"UPDATE",
        "id": id,
      }
      this.$refs.formRef.show(option);
    },
  }
};
</script>
